package com.jy.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jy.Dao.StudentDao;
import com.jy.Dao.impl.StudentDaoimpl;
import com.jy.entity.Student;
<<<<<<< HEAD
=======
import com.mysql.cj.util.Base64Decoder.IntWrapper;
>>>>>>> branch 'master' of https://gitee.com/HuangYuaa/studentgit.git


@WebServlet("/student/*")
public class StudentServlet extends BaseServlet {
	StudentDao dao=new StudentDaoimpl();
	protected void select(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("查询学生");
		
		List<Student> list=new ArrayList<>();
		try {
			list=dao.find();
			request.setAttribute("list", list);
			System.out.println(list);
			request.getRequestDispatcher("/select.jsp").forward(request, response);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	protected void insert(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("添加学生");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		int num=0;
		String name=request.getParameter("name");
		int age=Integer.parseInt(request.getParameter("age"));
		Student s=new Student(name,age);
		try {
		num=dao.add(s);
		} catch (Exception e) {
			e.printStackTrace();
		}if(num==0){
			System.out.println("添加失败！");
		}else{
			System.out.println("添加成功！");
		}
	}
}
